<template>
    <div v-if="isShow">
        <Select v-if="isKey" v-model="model" :placeholder="placeholder" :disabled="disabled">
            <Option v-for="item in list" @click.native="handleSelectChange(item)" :value="item.Dname + '' " :key="item.ID" :label="item.Dname">
                <span>{{ item.Dname }}</span>
                <span v-if="isYBCode" style="float:right;color:#2d8cf0">{{item.YBCode}}</span>
            </Option>
        </Select>
        <Select v-else v-model="model" :placeholder="placeholder" :disabled="disabled">
            <Option v-for="item in list" @click.native="handleSelectChange(item)" :value="item.ID + '' " :key="item.ID" :label="item.Dname">
                <span>{{ item.Dname }}</span>
                <span v-if="isYBCode" style="float:right;color:#2d8cf0">{{item.YBCode}}</span>
            </Option>
        </Select>
    </div>
</template>

<script>
import { getInfo } from './service'
export default {
    name: 'Dictionaries',
    props: [
        'value',
        'id',
        'currentModel',
        'name',
        'vague',
        'placeholder',
        'disabled',
        'isKey',
        'isYBCode'
    ],
    data() {
        return {
            model: '',
            list: [],
            isShow: false
        }
    },
    methods: {
        handleSelectChange(item) {
            this.$emit('setDictionaries', item.ID, this.value, item)
        }
    },
    created() {
        this.isShow = false
        getInfo({
            parentname: this.name
        }).then(res => {
            this.list = res.data.rows
            if (this.vague) {
                this.list.unshift({
                    ID: 0,
                    Dname: '全部'
                })
            }
            //this.currentModel
            this.model = this.currentModel

            this.isShow = true
        })
    }
}
</script>

<style>
</style>
